VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CSystemMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private mWnd As Window      ' Window whose WM_SYSCOMMAND messages we are going to track
Implements IsgMessageSink   ' Message sink implementation


' System command constants
' For a description of this commands take a look at the Win32 SDK
Const SC_SIZE = &HF000&
Const SC_MOVE = &HF010&
Const SC_MINIMIZE = &HF020&
Const SC_MAXIMIZE = &HF030&
Const SC_NEXTWINDOW = &HF040&
Const SC_PREVWINDOW = &HF050&
Const SC_CLOSE = &HF060&
Const SC_VSCROLL = &HF070&
Const SC_HSCROLL = &HF080&
Const SC_MOUSEMENU = &HF090&
Const SC_KEYMENU = &HF100&
Const SC_ARRANGE = &HF110&
Const SC_RESTORE = &HF120&
Const SC_TASKLIST = &HF130&
Const SC_SCREENSAVE = &HF140&
Const SC_HOTKEY = &HF150&
Const SC_DEFAULT = &HF160&
Const SC_MONITORPOWER = &HF170&
Const SC_CONTEXTHELP = &HF180&
Const SC_SEPARATOR = &HF00F&


Public Property Let hwnd(wnd As Long)
    On Error GoTo Error_
    
    If mWnd Is Nothing Then
        Set mWnd = New Window
    Else
        ' Disable all messages
        mWnd.EnableMessage wm_ALL, False
    End If
    
    mWnd.hwnd = wnd
    mWnd.EnableMessage wm_SYSCOMMAND
    mWnd.Callback = Me
    mWnd.Hooked = True
    
    Exit Property
Error_:
    MsgBox Error$
End Property

Public Property Get hwnd() As Long
    hwnd = mWnd.hwnd
End Property

Private Sub IsgMessageSink_Message(ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef result As Long)
    wParam = (wParam And &HFFF0)
    
    ' Disable screen saver
    Select Case wParam
        Case SC_SCREENSAVE
    
        Case SC_MAXIMIZE, SC_MINIMIZE
            
        Case SC_CLOSE
        
      Case Else
         result = mWnd.CallWindowProc(msg, wParam, lParam)
    End Select
End Sub


